package com.example.demo_mysql_mybatisplus.util.controller.advicer;

import com.example.demo_mysql_mybatisplus.util.controller.advicer.core.RestException;
import lombok.Getter;

/**
 * 异常枚举
 */
@Getter
public enum ErrorEnum {
    SUCCESS(0, "成功", "SUCCESS"),
    SYSTEM_ERROR(1, "系统异常", "SYSTEM ERROR"),

    API_CALL_FAIL(10, "接口调用失败", "FEIGN API CALL FAILED"),
    API_RETURN_ERROR(11, "接口返回异常", "FEIGN API RETURN ERROR"),

    PARAM_ERROR(100, "参数异常", "PARAM ERROR"),
    PARAMETERS_NOT_EXISTS(101, "参数不存在", "PARAMETERS IS NOT EXISTS "),

    NO_PERMISSION(200, "权限不足", "NO PERMISSION"),

    ;

    private Integer code;
    // 国际化
    private String cn;
    private String en;

    ErrorEnum(Integer code, String cn, String en) {
        this.code = code;
        this.cn = cn;
        this.en = en;
    }

    public Integer getCode() {
        return code;
    }
    /** 选择响应描述的国际化 */
    public String getDesc() {
        if("language"=="language1"){
            return cn;
        }else{
            return en;
        }
    }


    public void throwEx() {
        throw new RestException( this.code, this.getDesc() );
    }
    public void throwEx(String append2Desc) {
        throw new RestException( this.code, this.getDesc()+"("+append2Desc +")" );
    }
    public void throwEx(Integer code, String desc) {
        throw new RestException( code, desc);
    }


}

